var PATH_PREFIX ="";

function setPathPrefix(path){
	PATH_PREFIX =  path;
}
$(function(){
	WASP_WIDGET.initializeSelectStyle();
	WASP_WIDGET.registerResetClearEvent();
	WASP_WIDGET.triggerDateStyleWithYMD("#beginDate3");
	WASP_WIDGET.triggerDateStyleWithYMD("#endDate3");
    WASP_WIDGET.triggerCustInfoSelect("custNo3");
	WASP_WIDGET.triggerPrdInfoSelect("productId3");
});

var $custTradeChkReportList = $('#custTradeChkReportList');

$(function() {
	$custTradeChkReportList.jqGrid({   
		url:PATH_PREFIX + 'custTradeListPage.do', 
		/*caption:'客户交易明细对账列表<button type="button" class="btn btn-default btn-sm btn-small btn-fullscreen" title="" tabindex="-1"><i class="fa fa-arrows-alt icon-fullscreen"></i></button>',*/  
		datatype: "json",
		colNames:["id", "客户名称","产品名称","日期","交易类型","交易金额","交易份额","确认状态","确认金额","确认份额","费用"],        
		colModel:[  { name: 'tradeCheckId', index: 'tradeCheckId', key: true, hidden:true },       
		            { name: 'custName', index: 'custName', width: 30, resizable: true, sortable: false },
		            { name: 'productName', index: 'productName', width: 30, resizable: true, sortable: false },
		            { name: 'checkDate', index: 'checkDate', width: 30, resizable: true, sortable: false },
		            { name: 'tradeTypeName', index: 'tradeTypeName', width: 40, resizable: true, sortable: false },
		            { name: 'tradeAmount', index: 'tradeAmount', width: 30, resizable: true, sortable: false },
		            { name: 'tradePortion', index: 'tradePortion', width: 30, resizable: true, sortable: false },
		            { name: 'checkStatus', index: 'checkStatus', width: 30, resizable: true, sortable: false },
		            { name: 'checkAmount', index: 'checkAmount', width: 30, resizable: true, sortable: false },
		            { name: 'checkPortion', index: 'checkPortion', width: 30, resizable: true, sortable: false },
		            { name: 'cost', index: 'cost', width: 30, resizable: true, sortable: false }
				  ],
		rowNum: 20,
        rowList: [20, 30, 50],
        rownumbers: true,
        rownumWidth: 50,
        postData: {},
        prmNames: { search: "search", page: "pageNo", rows: "limit" },
        height: 'auto',
        width: false,
        autowidth:true,
        editurl: '',
        viewrecords: true,
        cellEdit: false,
        shrinkToFit: true,
        grouping: false,
        jsonReader: {
            root: "items", //结果集
            records: "total", //总记录数 
            total: "pageCount", //总页数
            page: "pageNo", //当前页 
            repeatitems: false // (4) 
        },  
		multiselect:false,
		pager: "#custTradeChkReportListPage",						
		viewrecords: true,
		hidegrid: false, 
		gridComplete: function(){
			var ids = $custTradeChkReportList.jqGrid('getDataIDs');
			for(var i = 0;i < ids.length;i++){
				var rowId = ids[i];
				$custTradeChkReportList.jqGrid('setRowData', ids[i]);
			}	
		}
	});
	$custTradeChkReportList.navGrid('#custTradeChkReportListPage',{edit:false,add:false,del:false,search:false,refreshstate:'current'});
	$custTradeChkReportList.jqGrid('setFrozenColumns');
	jqGridResize($custTradeChkReportList);
});

//绑定回车事件,查询
$("body").keypress(function(event){
	var key = event.which;
	if(key == "13"){
		queryByCondtion(true);
	}
});

function queryByCondtion3(flag) {
	var beginDate3 = $.trim($("#beginDate3").val());   
	var endDate3   = $.trim($("#endDate3").val());   
	var custNo3    = $.trim($("#custNo3").val()); 
	var productId3 = $.trim($("#productId3").val()); 
	var postData = $custTradeChkReportList.jqGrid("getGridParam", "postData");
    $.extend(postData, {
        'sp[beginDate]':beginDate3,
        'sp[endDate]':endDate3,
        'sp[productId]':productId3,
        'sp[custNo]':custNo3
    });
    if (flag) {
    	$custTradeChkReportList.jqGrid("setGridParam",{"datatype": "json"}).trigger("reloadGrid", [{ page: 1 }]); //重新载入Grid表格
    } else {
    	$custTradeChkReportList.jqGrid("setGridParam",{"datatype": "json"}).trigger("reloadGrid"); //重新载入Grid表格
    }
}
